package com.aube.plugin.guide;

import android.content.Context;
import android.graphics.BitmapFactory;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.aube.plugin.origin.R;
import com.huyn.baseframework.dynamicload.DLLayout;
import com.huyn.baseframework.dynamicload.IPositionManager;
import com.huyn.baseframework.utils.SharedPrefUtil;

/**
 * Created by huyaonan on 16/10/10.
 */
public class WidgetGuide extends DLLayout {

    public static final int GUIDE_VERSION_INT = 0;
    public static final String GUIDE_VERSION_STR = "GUIDE_VERSION_STR";

    private ImageView mImg;
    private TextView mText;

    public WidgetGuide(Context context) {
        super(context);
    }

    public WidgetGuide(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public WidgetGuide(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public void initViews() {
        inflate(R.layout.widget_guide, this, true);

        mImg = (ImageView) findViewById(R.id.guide_img);
        mText = (TextView) findViewById(R.id.guide_txt);

        mImg.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.guide));
        mText.setBackgroundDrawable(getResources().getDrawable(R.drawable.btn_next));
    }

    @Override
    public void fillData(Object o) {

    }

    @Override
    public void notifyAnim(int i) {

    }

    @Override
    public void registToManager(IPositionManager iPositionManager) {

    }

    @Override
    public void unreistFromManager(IPositionManager iPositionManager) {

    }

    @Override
    public int[] getLocations() {
        return new int[0];
    }

    /**
     * 第一个版本不需要
     * @param context
     * @return
     */
    public static boolean ifNeedShowGuide(Context context) {
//        int storedVersion = SharedPrefUtil.getInstance(context).getInt(GUIDE_VERSION_STR, -1);
//        boolean needGuide = true;
//        if(storedVersion >= GUIDE_VERSION_INT)
//            needGuide = false;
//        if(needGuide)
//            SharedPrefUtil.getInstance(context).putInt(GUIDE_VERSION_STR, GUIDE_VERSION_INT);
//        return needGuide;
        return false;
    }

    public void setGuideListener(final IGuideListener listener) {
        if(listener != null) {
            mText.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    listener.dismiss();
                }
            });
        }
    }

    public interface IGuideListener {
        public void dismiss();
    }

}
